home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / runtime / ml_state.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  7.8 KB  |  229 lines

  1. /* ml_state.h
  2.  *
  3.  * COPYRIGHT (c) 1990 by AT&T Bell Laboratories.
  4.  *
  5.  * This defines the layout of the ML state vector.  The ML state consists of
  6.  * the current allocation pointer (ml_allocptr), the heap limit pointer (ml_limitptr),
  7.  * the store list pointer (ML_storeptr), and a set of root registers (ml_roots[]).
  8.  * There are six or more distinguished root registers, which are arranged in a machine
  9.  * dependent fashion.
  10.  */
  11.  
  12. #ifndef _ML_STATE_
  13. #define _ML_STATE_
  14. #ifndef TRUE
  15. #define TRUE 1
  16. #define FALSE 0
  17. #endif TRUE
  18. #include "mask.h"
  19. #include <setjmp.h>
  20. #include "ml_signal.h"
  21. #include "mp.h"
  22.  
  23. /* NROOTS gives the size of the variable-size portion (roots[]) of the
  24.  * ML state vector. Note that the name "roots" is slightly misleading;
  25.  * while every entry in the vector must be saved over calls to C, not 
  26.  * every entry is a valid root on every entry to C.  
  27.  * The valididity of most entries is indicated using the register map
  28.  * convention (via ArgRegMap); these entries are valid (and live)
  29.  * iff the corresponding bit in the register mask is set (see 
  30.  * cps/generic.sml).
  31.  * N_ARG_REGS gives the number of such entries.
  32.  * The pc, exncont, varptr, and baseptr (if defined) are 
  33.  * always valid roots, and the icounter (if defined) never is.
  34.  */
  35.  
  36. #ifndef C
  37. #if defined(RS6000)
  38. #   define NROOTS        24           /* r6-r28,unused_slot */
  39. #   define N_ARG_REGS       19           /* (misc regs + 4) */
  40. #   define LINK_INDX        0
  41. #   define CLOSURE_INDX        1
  42. #   define ARG_INDX        2
  43. #   define CONT_INDX        3
  44. #   define EXN_INDX        4
  45. #   define VAR_INDX         5
  46. #   define BASE_INDX        6
  47. #   define PC_INDX        8
  48. #endif
  49.  
  50. #if defined(SPARC)
  51. #   define NROOTS        21        
  52. #   define N_ARG_REGS       17          /* exclude baseptr */
  53. #   define PC_INDX        0
  54. #   define EXN_INDX        7
  55. #   define ARG_INDX        1
  56. #   define CONT_INDX        2
  57. #   define CLOSURE_INDX        3
  58. #   define BASE_INDX        4
  59. #   define VAR_INDX         6
  60. #   define LINK_INDX        5
  61. #endif
  62.  
  63. #if defined(MIPS)
  64. #   define NROOTS        21        /* $2-$4, $30, pc, $5-$18,$20,$24 */
  65. #   define N_ARG_REGS       17          /* see run_ml.c */
  66. #   define PC_INDX        4
  67. #   define EXN_INDX        3        /* $30 */
  68. #   define ARG_INDX        0        /* $2 */
  69. #   define CONT_INDX        1        /* $3 */
  70. #   define CLOSURE_INDX        2        /* $4 */
  71. #   define VAR_INDX         19          /* $20 */
  72. #   define BASE_INDX        20          /* $24 */
  73. #   define LINK_INDX        5
  74. /* #   define ICOUNT_INDX   ??    */        
  75. /* #   define ICOUNT           1   */
  76. #endif    
  77.  
  78. #if defined(HPPA)
  79. #   define NROOTS        21        
  80. #   define N_ARG_REGS       16          /* 4 + length miscregs */
  81. #   define PC_INDX        0        /* = gclink */
  82. #   define EXN_INDX        7
  83. #   define ARG_INDX        1
  84. #   define CONT_INDX        2
  85. #   define CLOSURE_INDX        3
  86. #   define BASE_INDX        4
  87. #   define VAR_INDX         6
  88. #   define LINK_INDX        5        /* = stdlink */
  89. #endif
  90.  
  91. #if defined(M68)
  92. #   define NROOTS        8        /* d7, a0-a4, d3, pc */
  93. #   define N_ARG_REGS       5
  94. #   define PC_INDX        7
  95. #   define EXN_INDX        0        /* d7 */
  96. #   define ARG_INDX        1        /* a0 */
  97. #   define CONT_INDX        2        /* a1 */
  98. #   define CLOSURE_INDX        3        /* a2 */
  99. #   define VAR_INDX         6           /* d3 */
  100. #   define LINK_INDX        4
  101. #endif
  102.  
  103. #if defined(VAX)
  104. #   define NROOTS        12        /* r0-r7, r10, r13, pc (r15),varptr */
  105. #   define N_ARG_REGS       9
  106. #   define PC_INDX        10        /* a.k.a. r15 */
  107. #   define EXN_INDX        0        /* r13 */
  108. #   define ARG_INDX        1        /* r0 */
  109. #   define CONT_INDX        2        /* r1 */
  110. #   define CLOSURE_INDX        3        /* r2 */
  111. #   define VAR_INDX         11          /* varptr */
  112. #   define LINK_INDX        4
  113. #endif
  114.  
  115. #  if defined(NS32)
  116. #   define NROOTS
  117. #   define N_ARG_REGS       ?
  118. #   define PC_INDX        ?
  119. #   define EXN_INDX        ?        /* ?? */
  120. #   define ARG_INDX        ?        /* r0 */
  121. #   define CONT_INDX        ?        /* r1 */
  122. #   define CLOSURE_INDX        ?        /* r2 */
  123. #endif
  124.  
  125. #if defined(I386)
  126. #   define NROOTS        10
  127. #   define N_ARG_REGS        7
  128. #   define EXN_INDX        0        /* 8(esp) */
  129. #   define ARG_INDX        1        /* ebp       */
  130. #   define CONT_INDX        2        /* esi       */
  131. #   define CLOSURE_INDX        3        /* 16(esp) */
  132. #   define VAR_INDX        4        /* 28(esp) */ 
  133. #   define LINK_INDX        5        /* 20(esp) */
  134. #   define PC_INDX        6        /* eip       */
  135. /*  define MISC1        7 */    /* ebx       */
  136. /*  define MISC2        8 */    /* ecx       */
  137. /*  define MISC3        9 */    /* edx       */
  138. #endif
  139.  
  140. #else /* !C */
  141. #   define NROOTS          27          /* r5-r31 */
  142. #   define N_ARG_REGS      25
  143. #   define EXN_INDX        0           /* r5 */
  144. #   define PC_INDX         1           /* r6 */
  145. #   define CLOSURE_INDX    2           /* r7 */
  146. #   define ARG_INDX        3           /* r8 */
  147. #   define CONT_INDX       4           /* r9 */
  148. #   define LINK_INDX       5
  149. #endif /* !C */
  150.  
  151.  
  152. /* All ML values are represented by a (32-bit) word.  A value is either a tagged
  153.  * integer (unboxed), or a pointer to a heap object (boxed).
  154.  */
  155. typedef unsigned int *ML_val_t;
  156.  
  157. typedef struct {
  158.     int        ml_allocptr;        /* the pointer to the next word to allocate */
  159.     int        ml_limitptr;        /* the heap limit pointer */
  160.     int        ml_storeptr;        /* the list of store operations */
  161.     ML_val_t    ml_roots[NROOTS];    /* the root registers */
  162. #   define      ml_linkreg      ml_roots[LINK_INDX]
  163. #   define    ml_pc        ml_roots[PC_INDX]
  164. #   define    ml_exncont    ml_roots[EXN_INDX]
  165. #   define    ml_arg        ml_roots[ARG_INDX]
  166. #   define    ml_cont        ml_roots[CONT_INDX]
  167. #   define    ml_closure    ml_roots[CLOSURE_INDX]
  168. #ifdef VAR_INDX
  169. #   define      ml_varptr       ml_roots[VAR_INDX]
  170. #endif
  171. #ifdef BASE_INDX
  172. #   define    ml_baseptr    ml_roots[BASE_INDX]
  173. #endif
  174. #ifdef ICOUNT_INDX
  175. #   define      ml_icount       ml_roots[ICOUNT_INDX]
  176. #endif
  177. #ifdef I386
  178.     int        tempmem;          /* See I386.prim.s */
  179.     int        tempmem2;
  180. #endif
  181.     int         inML;                 /* in ML or C? */
  182.     int         request;              /* runtime service request code */
  183.     int         handlerPending;       /* signal handler pending? */
  184.     int         inSigHandler;         /* in a signal handler?    */
  185.     int         maskSignals;          /* signals masked?         */
  186.     int         NumPendingSigs;       /* number of pending signals */
  187.     int         ioWaitFlag;           /* waiting for an IO operation? */
  188.     int         GCpending;            /* indicates if GC is pending */
  189. #if defined(I386) 
  190.     int*        MLframe;              /* base address of ML stack frame */
  191. #else
  192. #if (!defined(MIPS) && !defined(C))   /* see lg */
  193.     int         unused;
  194. #endif
  195. #endif
  196.     int         self;                 /* proc id */
  197.     int         state;                /* RUNNING, SUSPENDED, or NO_PROC */
  198.     int         alloc_boundary;       /* end of arena for this proc */
  199.     int         max_allocptr;         /* max value of allocptr for this proc */
  200.     int         mask;                 /* live reg mask -- used in gc */
  201.     int         amount;               /* amount of space requested in gc */
  202.     int         SigCode;              /* last signal that hit         */
  203.     int         SigCount;             /* number of times signal has hit */
  204.     int         SigTbl[NUM_ML_SIGS];  /* status of the ML signals */
  205.     jmp_buf     SysCallEnv;           /* used to lngjmp out of IO operations */
  206.     ML_val_t    fault_exn;
  207. #ifdef SGI
  208.     int         lock_base;            /* base of lock allocation arena */
  209.     int         lock_top;             /* top of lock allocation arena */
  210.     int         lock_ptr;             /* next lock to return on allocation */
  211. #endif SGI
  212. } MLState_t;
  213.  
  214. typedef MLState_t *MLState_ptr;
  215.  
  216. #define ALL_ARGS_MASK    ((1 << N_ARG_REGS)-1)
  217. #define CONT_ARGS_MASK    contmask
  218.  
  219. /* This table maps the register numbers of the argument registers used by the
  220.  * code generator to the proper indices of the root vector.  The standard closure
  221.  * is in slot-0, the standard arg in slot-1 and the standard continuation is in
  222.  * slot-2.
  223.  */
  224. extern int    ArgRegMap[N_ARG_REGS];
  225.  
  226. /* Table is defined in ml_run.c */
  227.  
  228. #endif /* !_ML_STATE_ */
  229.